package com.sander.guardmanagement.ui.view;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.sander.guardmanagement.R;
import com.sander.guardmanagement.model.City;
import com.sander.guardmanagement.model.District;
import com.sander.guardmanagement.response.ResponseHomeGetCommunityData;
import com.sander.guardmanagement.ui.model.DistrictItem;

import java.util.List;

/**
 * Created by sander on 2017/4/10.
 */

public class DistrictListAdapter extends BaseAdapter {
   public List<ResponseHomeGetCommunityData> list;

    Context context;

    private final LayoutInflater layoutInflater;
    public DistrictListAdapter(Context context, List<ResponseHomeGetCommunityData> list){
        this.context = context;
        this.list = list;
        layoutInflater = LayoutInflater.from(context);
    }
    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        DistrictItem item = null;
        if (convertView == null){
            convertView = layoutInflater.inflate(R.layout.districitunitbbbitem,parent,false);
            TextView textView = (TextView) convertView.findViewById(R.id.distrivtsimpleText);
            item = new DistrictItem();
            item.setTextView(textView);
            convertView.setTag(item);
        }else{
             item = (DistrictItem)convertView.getTag();
        }
        ResponseHomeGetCommunityData district = list.get(position);
        item.getTextView().setText(district.getCommunity());
        return convertView;
    }
}
